package com.sec.bnjey.activity;

import java.io.IOException;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.sec.bnjey.BaseActivity;
import com.sec.bnjey.R;

public class UserAgreementActivity extends BaseActivity implements
		OnClickListener {

	public static final String KEY_AGREE = "key_agree";
	boolean check = true;
	boolean agree_check = false;

	/** Called when the activity is first created. */
	@SuppressWarnings("null")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.useragreementactivity);

		Toast.makeText(UserAgreementActivity.this,
				"Vtalk 서비스 이용을 하기 위해선 사용자의 동의가 필요합니다. 동의체크를 하신후 다음 버튼을 누르세요",
				Toast.LENGTH_LONG).show();
		initialize();

	}

	private void AMCommand(String command) {
		try {
			Runtime.getRuntime().exec(command);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}

	}

	private void initialize() {

		// 상단메뉴 투명한것으로 교체

		TextView tv = (TextView) findViewById(R.id.TV_TopMenu_Title);
		tv.setText("동의");
		Button b = (Button) findViewById(R.id.B_TopMenu_Left);
		b.setMinWidth(64);
		b.setBackgroundResource(R.drawable.top_home_selector);
		b.setOnClickListener(this);

		b = (Button) findViewById(R.id.AGREE1_Btn);
		b.setOnClickListener(this);
		b = (Button) findViewById(R.id.btn);
		b.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.B_TopMenu_Left:
			finish();
			break;

		case R.id.AGREE1_Btn:

			startActivity(new Intent(UserAgreementActivity.this,
					UserAgreementDetailActivity.class));
			overridePendingTransition(0, 0);


			break;


		case R.id.btn:
			final CheckBox CB1 = (CheckBox) findViewById(R.id.toggle1);
			final CheckBox CB2 = (CheckBox) findViewById(R.id.toggle2);
			final CheckBox CB3 = (CheckBox) findViewById(R.id.toggle3);

			if (CB1.isChecked() && CB2.isChecked() && CB3.isChecked()) {// 3개
																		// 체크가
																		// 된후

				overridePendingTransition(0, 0);
				finish();
			} else {
				Toast.makeText(UserAgreementActivity.this,
						"약관 동의가 있어야 Vtalk서비스를 이용할수 있습니다", Toast.LENGTH_SHORT)
						.show();
			}
			break;

		// string.xml파일저장된 내용
		// <string
		// name="Theme_LeftSpinner">Theme:</string>
		//
		//
		// 이런식으로 호출해서 string 으로 읽어옵니다.
		//
		// String strTheme = getResources().getString(R.string.agree1);

		}
	}

	@Override
	public void onBackPressed() {

		InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		mgr.showSoftInput(this.getCurrentFocus(),
				InputMethodManager.SHOW_FORCED);
	}

	class MileageDBHelper2 extends SQLiteOpenHelper {
		public MileageDBHelper2(Context context) {
			super(context, "Mileage50.db", null, 1);
		}

		public void onCreate(SQLiteDatabase db) {
			db.execSQL("CREATE TABLE dic (title TEXT)");

		}

		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			db.execSQL("DROP TABLE IF EXISTS dic");
			onCreate(db);
		}
	}

}